home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / prog / amisl090.zip / VGABLANK.ASM < prev   
Assembly Source File  |  1992-09-12  |  6KB  |  261 lines

  1. ;-----------------------------------------------------------------------
  2. ; VGABLANK.ASM    Public Domain 1992 Ralf Brown
  3. ;        You may do with this software whatever you want, but
  4. ;        common courtesy dictates that you not remove my name
  5. ;        from it.
  6. ;
  7. ; Minimalist VGA screen blanker.
  8. ;
  9. ; Version 0.90
  10. ; LastEdit: 9/12/92
  11. ;-----------------------------------------------------------------------
  12.  
  13. __TINY__ equ 1                ; using Tiny model
  14.     INCLUDE AMIS.MAC
  15.  
  16.     @Startup 2,00                 ; need DOS 2.00                     
  17.                     ; this macro also takes care of declaring
  18.                     ; all the segments in the required order
  19.  
  20. ;-----------------------------------------------------------------------
  21. ;
  22. VERSION_NUM equ 005Ah    ; v0.90
  23. VERSION_STR equ "0.90"
  24.  
  25. ;-----------------------------------------------------------------------
  26. ;
  27. ; useful macros
  28. ;
  29. LODSB_ES MACRO
  30.     DB 26h,0ACh    ; LODSB ES:
  31.     ENDM
  32.  
  33. ;-----------------------------------------------------------------------
  34. ; Declare the additional segments we will use
  35. ;
  36.  
  37. BIOS_SEG SEGMENT AT 40h
  38.     ORG 63h
  39. video_base dw ?
  40. BIOS_SEG ENDS
  41.  
  42. ;-----------------------------------------------------------------------
  43. ; Useful definitions
  44. ;
  45. VIDEO_DISABLE_BIT equ 20h
  46. VGA_REG       equ 3C4h
  47. TICKS_PER_MINUTE equ 0444h
  48.  
  49. ;-----------------------------------------------------------------------
  50. ; Put the resident code into its own segment so that all the offsets are
  51. ; proper for the new location after copying it into a UMB or down into
  52. ; the PSP.
  53. ;
  54. TSRcode@
  55. start_TSRcode label byte
  56.  
  57. ;-----------------------------------------------------------------------
  58. ; Declare the interrupt vectors hooked by the program, then set up the
  59. ; Alternate Multiplex Interrupt Spec handler
  60. ;
  61.     HOOKED_INTS 09h,1Ch
  62.     ALTMPX    'Ralf B','VGABLANK',VERSION_NUM
  63.  
  64. ;-----------------------------------------------------------------------
  65. ; Now the meat of the resident portion, the keyboard and timer tick
  66. ; interrupt handlers.
  67. ; We can save two bytes by specifying the hardware reset handler set up by
  68. ; the ALTMPX macro above
  69. ;
  70. time_count  dw 0            ; patched to actual timeout tick count
  71. video_state db 0
  72.  
  73. set_video_state:
  74.     push    dx
  75.     mov    dx,VGA_REG
  76.     mov    al,1
  77.     out    dx,al
  78.     inc    dx
  79.     in    al,dx
  80.     dec    dx
  81.     mov    video_state,ah
  82.     and    al,not VIDEO_DISABLE_BIT
  83.     or    ah,al
  84.     mov    al,1
  85.     out    dx,al
  86.     inc    dx
  87.     mov    al,ah
  88.     out    dx,al
  89.     pop    dx
  90.     ret
  91.  
  92. ISP_HEADER 1Ch,hw_reset_2Dh
  93.     sti                ; allow interrupts
  94.     dec    time_count        ; count down, and each time we hit
  95.     jnz    int1C_done        ; zero, force the video off
  96.     push    ax
  97.     mov    ah,VIDEO_DISABLE_BIT
  98.     call    set_video_state
  99.     pop    ax
  100. int1C_done:
  101.     JMP    ORIG_INT1Ch
  102.  
  103. ISP_HEADER 09h,hw_reset_2Dh
  104.     sti                ; allow interrupts
  105.         push    ax                      ; keystroke, so unblank display
  106.     mov    ah,0
  107.     cmp    ah,video_state        ; don't unblank unless currently blanked
  108.     je    int09_done        ; because of sparkles on some displays
  109.         call    set_video_state
  110. int09_done:
  111.     pop    ax
  112.     mov    time_count,0FFFFh    ; patched with actual timeout count
  113. MAX_TIME equ word ptr ($-2)
  114.     jmp    ORIG_INT09h
  115.  
  116. resident_code_size equ offset $
  117.  
  118. TSRcodeEnd@
  119.  
  120. ;-----------------------------------------------------------------------
  121.  
  122. _TEXT SEGMENT 'CODE'
  123.     ASSUME cs:_TEXT,ds:NOTHING,es:NOTHING,ss:NOTHING
  124.  
  125. banner       db 'VGABLANK v',VERSION_STR,'  Public Domain 1992 Ralf Brown',13,10,'$'
  126. usage_msg  db 'Usage:',9,'VGABLANK n',9,"(n=1-9) install to blank after 'n' minutes",13,10
  127.        db 9,'VGABLANK R',9,'remove from memory',13,10
  128.        db "$"
  129. need_VGA_msg     db "This program requires a VGA.",13,10,"$"
  130. installed_msg    db "Installed.",13,10,"$"
  131. already_inst_msg db "Different version already installed.",13,10,"$"
  132. timeout_changed_msg db "Blanking time changed.",13,10,"$"
  133. cant_remove_msg  db "Can't remove from memory.",13,10,"$"
  134. uninstalled_msg  db "Removed.",13,10,"$"
  135.  
  136. timeout        dw ?
  137.  
  138.  
  139.     @Startup2    Y
  140.     push    ds
  141.     pop    es
  142.     ASSUME    ES:_INIT
  143.     push    cs
  144.     pop    ds
  145.     ASSUME    DS:_TEXT
  146.     ;
  147.     ; say hello 
  148.     ;
  149.     DISPLAY_STRING banner
  150.     mov    bx,1000h        ; set memory block to 64K
  151.     mov    ah,4Ah
  152.     int    21h
  153.     mov    si,81h            ; SI -> command line
  154.     cld                ; ensure proper direction for string ops
  155. cmdline_loop:
  156.     lodsb_es
  157.     cmp    al,' '            ; skip blanks and tabs on commandline
  158.     je    cmdline_loop
  159.     cmp    al,9
  160.     je    cmdline_loop
  161.     cmp    al,'1'            ; number of minutes specified?
  162.     jb    not_digit
  163.     cmp    al,'9'            ; if digit, go install TSR
  164.     jbe    installing
  165. not_digit:
  166.     and    al,0DFh            ; force to uppercase
  167.     cmp    al,'R'
  168.     je    removing
  169. usage:
  170.     mov    dx,offset _TEXT:usage_msg
  171.     jmp     exit_with_error
  172.  
  173. removing:
  174.     UNINSTALL cant_uninstall
  175.     ;
  176.     ; force video back on in case we are called from a batch file while
  177.     ; the screen is blanked
  178.     ;
  179.     mov    dx,VGA_REG
  180.     mov    al,1
  181.     out    dx,al
  182.     inc    dx
  183.     in    al,dx
  184.     dec    dx
  185.     and    al,not VIDEO_DISABLE_BIT
  186.     mov    ah,al
  187.     mov    al,1
  188.     out    dx,al
  189.     inc    dx
  190.     mov    al,ah
  191.     out    dx,al
  192.     ;
  193.     ; finally, announce that the resident part has been removed
  194.     ;
  195.     push    cs
  196.     pop    ds
  197.     ASSUME    DS:_TEXT
  198.     DISPLAY_STRING uninstalled_msg
  199. successful_exit:
  200.         mov     ax,4C00h
  201.     int    21h
  202.  
  203. installing:
  204.     sub    al,'0'
  205.     cbw
  206.     mov    bx,TICKS_PER_MINUTE
  207.     mul    bx
  208.     mov    timeout,ax        ; and remember for later
  209.     mov    ax,1A00h        ; get display combination code
  210.     int    10h
  211.     cmp    al,1Ah            ; supported? (i.e. VGA present?)
  212.     mov    dx,offset _TEXT:need_VGA_msg
  213.     jne    exit_with_error
  214.     ;
  215.     ; place any necessary pre-initialization here
  216.     ;
  217.     INSTALL_TSR ,BEST,TOPMEM,inst_patch,already_installed
  218.  
  219. cant_uninstall:
  220.     mov    dx,offset _TEXT:cant_remove_msg
  221. exit_with_error:
  222.     mov    ah,9
  223.     int    21h
  224.     mov    ax,4C01h
  225.     int    21h
  226.  
  227. already_installed:
  228.     cmp    cx,VERSION_NUM        ; same version installed?
  229.     jne    wrong_version
  230.     mov    al,0            ; request signature string
  231.     int    2Dh
  232.     mov    es,dx            ; ES -> resident code
  233.     ASSUME    ES:RESIDENT_CODE
  234.     mov    ax,timeout
  235.     mov    time_count,ax
  236.     mov    MAX_TIME,ax
  237.     DISPLAY_STRING timeout_changed_msg
  238.     jmp    successful_exit
  239.  
  240. wrong_version:
  241.     ASSUME    ES:NOTHING
  242.     mov    dx,offset _TEXT:already_inst_msg
  243.     jmp     exit_with_error
  244.  
  245. inst_patch:
  246.     push    es
  247.     mov    es,ax
  248.     ASSUME    ES:RESIDENT_CODE
  249.     mov    ax,timeout
  250.     mov    time_count,ax
  251.     mov    MAX_TIME,ax
  252.     pop    es
  253.     ASSUME    ES:NOTHING
  254.     DISPLAY_STRING installed_msg
  255.     ret
  256.  
  257. _TEXT ENDS
  258.  
  259.      end INIT
  260.  
  261.